// Copyright 2013 Ronald Schlenker, www.technewlogic.de.
// 
// This file is part of Byond.
// 
// Byond is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
// 
// Byond is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with Byond.  If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Text;
using System.Windows.Input;
using Jacobi.Vst.Core;

namespace Byond.Vst
{
	static class Extensions
	{
		public static Key ToWpfKey(this VstVirtualKey key)
		{
			switch (key)
			{
				case VstVirtualKey.VKEY_NONE:
					return Key.None;
				case VstVirtualKey.VKEY_BACK:
					return Key.Back;
				case VstVirtualKey.VKEY_TAB:
					return Key.Tab;
				case VstVirtualKey.VKEY_CLEAR:
					return Key.Clear;
				case VstVirtualKey.VKEY_RETURN:
					return Key.Return;
				case VstVirtualKey.VKEY_PAUSE:
					return Key.Pause;
				case VstVirtualKey.VKEY_ESCAPE:
					return Key.Escape;
				case VstVirtualKey.VKEY_SPACE:
					return Key.Space;
				case VstVirtualKey.VKEY_NEXT:
					return Key.Next;
				case VstVirtualKey.VKEY_END:
					return Key.End;
				case VstVirtualKey.VKEY_HOME:
					return Key.Home;
				case VstVirtualKey.VKEY_LEFT:
					return Key.Left;
				case VstVirtualKey.VKEY_UP:
					return Key.Up;
				case VstVirtualKey.VKEY_RIGHT:
					return Key.Right;
				case VstVirtualKey.VKEY_DOWN:
					return Key.Down;
				case VstVirtualKey.VKEY_PAGEUP:
					return Key.PageUp;
				case VstVirtualKey.VKEY_PAGEDOWN:
					return Key.PageDown;
				case VstVirtualKey.VKEY_SELECT:
					return Key.Select;
				case VstVirtualKey.VKEY_PRINT:
					return Key.Print;
				case VstVirtualKey.VKEY_ENTER:
					return Key.Enter;
				case VstVirtualKey.VKEY_SNAPSHOT:
					return Key.Snapshot;
				case VstVirtualKey.VKEY_INSERT:
					return Key.Insert;
				case VstVirtualKey.VKEY_DELETE:
					return Key.Delete;
				case VstVirtualKey.VKEY_HELP:
					return Key.Help;
				case VstVirtualKey.VKEY_NUMPAD0:
					return Key.NumPad0;
				case VstVirtualKey.VKEY_NUMPAD1:
					return Key.NumPad1;
				case VstVirtualKey.VKEY_NUMPAD2:
					return Key.NumPad2;
				case VstVirtualKey.VKEY_NUMPAD3:
					return Key.NumPad3;
				case VstVirtualKey.VKEY_NUMPAD4:
					return Key.NumPad4;
				case VstVirtualKey.VKEY_NUMPAD5:
					return Key.NumPad5;
				case VstVirtualKey.VKEY_NUMPAD6:
					return Key.NumPad6;
				case VstVirtualKey.VKEY_NUMPAD7:
					return Key.NumPad7;
				case VstVirtualKey.VKEY_NUMPAD8:
					return Key.NumPad8;
				case VstVirtualKey.VKEY_NUMPAD9:
					return Key.NumPad9;
				case VstVirtualKey.VKEY_MULTIPLY:
					return Key.Multiply;
				case VstVirtualKey.VKEY_ADD:
					return Key.Add;
				case VstVirtualKey.VKEY_SEPARATOR:
					return Key.Separator;
				case VstVirtualKey.VKEY_SUBTRACT:
					return Key.Subtract;
				case VstVirtualKey.VKEY_DECIMAL:
					return Key.Decimal;
				case VstVirtualKey.VKEY_DIVIDE:
					return Key.Divide;
				case VstVirtualKey.VKEY_F1:
					return Key.F1;
				case VstVirtualKey.VKEY_F2:
					return Key.F2;
				case VstVirtualKey.VKEY_F3:
					return Key.F3;
				case VstVirtualKey.VKEY_F4:
					return Key.F4;
				case VstVirtualKey.VKEY_F5:
					return Key.F5;
				case VstVirtualKey.VKEY_F6:
					return Key.F6;
				case VstVirtualKey.VKEY_F7:
					return Key.F7;
				case VstVirtualKey.VKEY_F8:
					return Key.F8;
				case VstVirtualKey.VKEY_F9:
					return Key.F9;
				case VstVirtualKey.VKEY_F10:
					return Key.F10;
				case VstVirtualKey.VKEY_F11:
					return Key.F11;
				case VstVirtualKey.VKEY_F12:
					return Key.F12;
				case VstVirtualKey.VKEY_NUMLOCK:
					return Key.NumLock;
				case VstVirtualKey.VKEY_SCROLL:
					return Key.Scroll;
				case VstVirtualKey.VKEY_SHIFT:
					return Key.LeftShift;
				case VstVirtualKey.VKEY_CONTROL:
					return Key.LeftCtrl;
				case VstVirtualKey.VKEY_ALT:
					return Key.LeftAlt;
				case VstVirtualKey.VKEY_EQUALS:
					return Key.Enter; // TODO: Was ist das?
				default:
					throw new ArgumentOutOfRangeException("key");
			}
		}
	
		public static Key ToWpfKey(this byte ascii)
		{
			var s = Encoding.ASCII.GetString(new[] { ascii });
			return (Key)(new KeyConverter().ConvertFromInvariantString(s));
		}
		
		public static byte Base2(this string me)
		{
			return Convert.ToByte(me, 2);
		}
	}
}